package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ColorUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.LeadCarType;
import com.ygxsk.carhome.response.LeadListItemBean;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.util.List;

public class LeadListItemAdapter extends BaseQuickAdapter<LeadListItemBean, BaseViewHolder> {

//    public LeadListItemAdapter(int layoutResId) {
//        super(layoutResId);
//    }

    public LeadListItemAdapter(int layoutResId, @Nullable List<LeadListItemBean> data) {
        super(layoutResId, data);
        //设置点击事件；
//        addChildClickViewIds(R.id.materialripplelayoutoutsidelead, R.id.textvieweditviewphone);
        addChildClickViewIds(R.id.textvieweditviewphone);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, LeadListItemBean leadListItemBean) {

        //设置item数据；
        //获取名字
        String name = leadListItemBean.getCustomerName();

        //获取电话
        String phone = leadListItemBean.getCustomerPhone();

        //添加星星之后的
        String phoneStar = StringCodeUtils.mobileEncrypt(phone);


        //获取这个条目的状态
        String stateItem = leadListItemBean.getStatusName();
        //单个的汽车的类型
        String stateCar = leadListItemBean.getLatentTypeName();
        //客户来源的标签
        String stateFromWhere = leadListItemBean.getCreatesourceName();

        //车辆的类型： 1是新车；2是二手车；
        String latentType = leadListItemBean.getLatentType();

        //findViews

        //名称
        TextView textViewPersonName = (TextView) baseViewHolder.getView(R.id.textviewpersonnaminleadada);

        //车辆的类型：新车 还是二手车
        RoundTextView textViewStateCarInfo = (RoundTextView) baseViewHolder.getView(R.id.textviewstatecarinfo);
        //人员来源的状态
        RoundTextView textViewLeadFormWhere = (RoundTextView) baseViewHolder.getView(R.id.textviewleadformwhere);

        //该条目状态
        TextView textViewPhone = (TextView) baseViewHolder.getView(R.id.textvieweditviewphone);
        //人员的分配状态
        TextView textViewPersonAssignedState = (TextView) baseViewHolder.getView(R.id.textviewpersonassignedstate);

        //名称
        CommUtils.setText(textViewPersonName, name);

        //如果是【新车】类型，就是蓝色标签，
        //如果是【二手车】类型，就是浅黄标签

//        LeadCarType {
//            LEADTYPE_CAR_NEW("1", "新车"),
//            LEADTYPE_CAR_OLD("2", "二手车");

        if (TextUtils.equals(LeadCarType.LEADTYPE_CAR_NEW.getIndex(), latentType)) {
            //新车：蓝色圈圈
            textViewStateCarInfo.setTextColor(ColorUtils.getColor(R.color.headmanblue));
            textViewStateCarInfo.getDelegate().setStrokeColor(ColorUtils.getColor(R.color.headmanblue));

        } else if (TextUtils.equals(LeadCarType.LEADTYPE_CAR_OLD.getIndex(), latentType)) {
            //二手车：浅黄圈圈
            textViewStateCarInfo.setTextColor(ColorUtils.getColor(R.color.gold5));
            textViewStateCarInfo.getDelegate().setStrokeColor(ColorUtils.getColor(R.color.gold5));
        }


        if (!TextUtils.isEmpty(stateCar)) {
            CommUtils.setViewVisible(textViewStateCarInfo);
            //车子的状态
            CommUtils.setText(textViewStateCarInfo, stateCar);
        } else {
            CommUtils.setViewGone(textViewStateCarInfo);
            //车子的状态
            CommUtils.setText(textViewStateCarInfo, "");
        }

        if (!TextUtils.isEmpty(stateFromWhere)) {
            CommUtils.setViewVisible(textViewLeadFormWhere);
            //客户的来源
            CommUtils.setText(textViewLeadFormWhere, stateFromWhere);
        } else {
            CommUtils.setViewGone(textViewLeadFormWhere);
            //客户的来源
            CommUtils.setText(textViewLeadFormWhere, "");
        }

        //手机号
        CommUtils.setText(textViewPhone, phoneStar);
        //该客户的分配状态
        CommUtils.setText(textViewPersonAssignedState, stateItem);

    }


}
